package ast.nodes.commandNodes;

import scanner.Token;
import ast.ASTNode;
import ast.Evaluation;
import ast.nodes.CommandNode;
import ast.nodes.ParameterNode;

public class PrintNode extends CommandNode {

    public PrintNode()
    {
        super();
    }
    
    public PrintNode(Token data)
    {
        super(data);
    }

    /**
     * The action print accepts either a string literal or the variable
     * LINE (representing the line being modified).
     */
    @Override
    public void run(Evaluation input) throws Exception {
        for(ASTNode child : children)
            if(child instanceof ParameterNode)
            {
                switch(child.getData().getType())
                {
                    case LINE:
                        input.print(input.getCurrentLine());
                        break;
                    case QUOTED_STRING:
                        String ts = child.getData().getTokenString();
                        input.print(ts.substring(1, ts.length() - 1));
                        break;
                }
            }
    }
}
